/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jdCosteoDiario.java
 *
 * Created on 10-dic-2010, 12:36:36
 */
package Costos;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.VerificarDatos;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JList;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
import javax.swing.text.NumberFormatter;
import suministros.ejb30.TO.ElementoCostoTO;
import suministros.ejb30.TO.ProveedorTO;
import suministros.ejb30.TO.SuministroTO;
import suministros.ejb30.entity.CosteoDiario;
import suministros.ejb30.entity.ElementoCosto;
import suministros.ejb30.entity.Proveedor;
import suministros.ejb30.entity.Suministros;

/**
 *
 * @author Luis_Angel
 */
public class jdCosteoDiario extends javax.swing.JDialog {

    private ListDataIntelliHints intelliHintsProveedor;
    private ListDataIntelliHints intelliHintsSuministros;
    private SuministroTO suministro;
    private DefaultFormatterFactory currFactory;
    private MaskFormatter mascaraRuc;
    private MaskFormatter mascaraFechaIngreso;
    private CosteoDiario costeo;

    /** Creates new form jdCosteoDiario */
    public jdCosteoDiario(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        construirMascaras();
        initComponents();
        try {
            cargaHintsIndependientes();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        llenarComboElemento();
    }

    public void setAdmin(CosteoDiario costo) {
        this.jtfCantidad.setText("" + costo.getCantidad().doubleValue());
        this.jftMonto_dolares.setText("" + costo.getMontoDolares().doubleValue());
        this.jtfDescripcion.setText(costo.getDescripcion());
        this.jtfFecha.setText(costo.getFecha());
        this.jtxRucProveedor.setText(costo.getCodProveedor().getCodProveedor());
        //
        this.costeo = costo;
        //elementos
        for (ElementoCostoTO TI : cboBeanBindingElementoCosto1.getLista()) {
            if (TI.getId().equalsIgnoreCase(costo.getIdElementoCosto().getIdElementoCosto())) {
                this.jcboElemento.setSelectedItem(TI);
                break;
            }
        }
        this.jtfCodSuministro.setText(costo.getIdSuministro().getIDSuministro());

        buscarRazonSocial();
        buscarSuministros();
    }

    private void llenarComboElemento() {
        List listaElementos = null;
        List listaElementos_cbo = this.cboBeanBindingElementoCosto1.getLista();
        listaElementos_cbo.clear();
        try {
            listaElementos = GestionPedidosDelegate.getInstance().getListaElementosCosto();
            this.cboBeanBindingElementoCosto1.setLista(listaElementos);
            this.bindingGroup.bind();
            this.jcboElemento.updateUI();
            this.jcboElemento.setSelectedIndex(0);
        } catch (Exception ex) {
            Utiles_MensajesDialogo.mensajeAlerta("Error al obtener elementos\n" + ex.getMessage());
            ex.printStackTrace();
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void construirMascaras() {
        try {
            this.mascaraRuc = new MaskFormatter("###########");
            this.mascaraFechaIngreso = new MaskFormatter("##/##/####");
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        NumberFormat editFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);

        editFormat.setGroupingUsed(false);

        NumberFormatter enFormat = new NumberFormatter(editFormat);

        this.currFactory = new DefaultFormatterFactory(enFormat, enFormat, enFormat);

        enFormat.setAllowsInvalid(true);
    }

    private void cargaHintsIndependientes() throws Exception {
        this.intelliHintsProveedor = new ListDataIntelliHints(this.jtxProveedor, Listas.getProveedores());
        ((JList) this.intelliHintsProveedor.getDelegateComponent()).setFixedCellWidth(300);
        this.intelliHintsSuministros = new ListDataIntelliHints(this.jtfDescSuministro, Listas.getSuministros());
        ((JList) this.intelliHintsSuministros.getDelegateComponent()).setFixedCellWidth(300);
    }

    private void buscarSuministros() {
        this.suministro = null;
        SuministroTO sumi;
        if (this.jtfCodSuministro.getText().trim().length() < 1) {

            try {
                sumi = (SuministroTO) this.intelliHintsSuministros.getSelectedHint();
            } catch (NullPointerException ex) {
                sumi = null;
            }
        } else {
            sumi = Listas.getSuministroCodigo(this.jtfCodSuministro.getText().trim());
        }

        if (sumi == null) {
            Utiles_MensajesDialogo.mensajeError("El suministro no existe!");
            this.jtfDescSuministro.setText("");

        } else {
            this.jtfDescSuministro.setText(sumi.toString());
            this.jtfCodSuministro.setText(sumi.getId_suministro());

        }
    }

    private void buscarRazonSocial() {
        ProveedorTO pro;
        if (this.jtxRucProveedor.getText().trim().length() < 1) {
            try {
                pro = (ProveedorTO) this.intelliHintsProveedor.getSelectedHint();
            } catch (NullPointerException ex) {
                pro = null;
            }
        } else {
            pro = Listas.getProveedorcodigo(this.jtxRucProveedor.getText().trim());
        }
        if (pro == null) {
            Utiles_MensajesDialogo.mensajeError("El proveedor no existe!");
            this.jtxRucProveedor.setText("");
            pro = null;
        } else {
            this.jtxProveedor.setText(pro.getRazon() + " - " + pro.getCodProveedor());
            this.jtxRucProveedor.setText(pro.getCodProveedor());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingElementoCosto1 = new Costos.CboBeanBindingElementoCosto();
        jbGuardar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jtfCodSuministro = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jtfDescSuministro = new javax.swing.JTextField();
        jtxRucProveedor = new javax.swing.JFormattedTextField(this.mascaraRuc);
        jLabel18 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtxProveedor = new javax.swing.JTextField();
        jtfFecha = new javax.swing.JFormattedTextField(this.mascaraFechaIngreso);
        jtfCantidad = new javax.swing.JTextField();
        jftMonto_dolares = new javax.swing.JTextField();
        jlblMoneda = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jcboElemento = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jtfDescripcion = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jbGuardar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jbGuardar.setText("Guardar");
        jbGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGuardarActionPerformed(evt);
            }
        });
        jbGuardar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbGuardarKeyPressed(evt);
            }
        });

        jbCancelar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jbCancelar.setText("Cancelar");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jbCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbCancelarKeyPressed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel9.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel9.setText("COD.Suministro");

        jtfCodSuministro.setFont(new java.awt.Font("Arial 12 Simple 12 Simple", 0, 12));
        jtfCodSuministro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCodSuministroActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel10.setText("Desc.Suministro");

        jtfDescSuministro.setFont(new java.awt.Font("Arial 12 Simple 12 Simple", 0, 12));
        jtfDescSuministro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfDescSuministroActionPerformed(evt);
            }
        });
        jtfDescSuministro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfDescSuministroKeyPressed(evt);
            }
        });

        jtxRucProveedor.setFont(new java.awt.Font("Arial", 0, 12));
        jtxRucProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxRucProveedorActionPerformed(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel18.setText("RUC"); // NOI18N

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel7.setText("Proveedor"); // NOI18N

        jtxProveedor.setFont(new java.awt.Font("Arial", 0, 12));
        jtxProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxProveedorActionPerformed(evt);
            }
        });
        jtxProveedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtxProveedorKeyPressed(evt);
            }
        });

        jtfFecha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfFechaKeyPressed(evt);
            }
        });

        jtfCantidad.setFont(new java.awt.Font("Arial", 0, 12));
        jtfCantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCantidadActionPerformed(evt);
            }
        });

        jftMonto_dolares.setFont(new java.awt.Font("Arial", 0, 12));
        jftMonto_dolares.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jftMonto_dolaresActionPerformed(evt);
            }
        });

        jlblMoneda.setFont(new java.awt.Font("Arial", 1, 12));
        jlblMoneda.setText("Monto Dolares"); // NOI18N

        jLabel11.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel11.setText("Cantidad"); // NOI18N

        jLabel8.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel8.setText("Fecha"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("Elemento Costo"); // NOI18N

        jcboElemento.setFont(new java.awt.Font("Arial", 0, 12));
        jcboElemento.setToolTipText("Ubicaciones dentero de un Almacen"); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingElementoCosto1, eLProperty, jcboElemento);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboElemento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboElementoActionPerformed(evt);
            }
        });
        jcboElemento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboElementoKeyPressed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel12.setText("Descripcion"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(10, 10, 10)
                        .addComponent(jtfCodSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                        .addComponent(jtfDescSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel8)
                            .addComponent(jLabel18))
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jtxRucProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(24, 24, 24)
                                .addComponent(jtxProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jtfDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(78, 78, 78)
                                        .addComponent(jLabel6))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jtfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(99, 99, 99)
                                        .addComponent(jlblMoneda)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jftMonto_dolares, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jcboElemento, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabel9))
                    .addComponent(jtfCodSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfDescSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))))
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxRucProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jtxProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jcboElemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jtfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jlblMoneda))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jftMonto_dolares, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(260, 260, 260)
                        .addComponent(jbGuardar)
                        .addGap(3, 3, 3)
                        .addComponent(jbCancelar)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbCancelar, jbGuardar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbGuardar)
                    .addComponent(jbCancelar))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGuardarActionPerformed
        try {
            if (this.costeo == null) {
                costeo = new CosteoDiario();
            }
            costeo.setCantidad(new BigDecimal(this.jtfCantidad.getText().trim()));
            costeo.setCodProveedor(new Proveedor(this.jtxRucProveedor.getText().trim()));
            costeo.setFecha(jtfFecha.getText().trim());
            costeo.setDescripcion(jtfDescripcion.getText().trim());
            costeo.setIdSuministro(new Suministros(this.jtfCodSuministro.getText().trim()));
            costeo.setMontoDolares(new BigDecimal(jftMonto_dolares.getText().trim()));
            ElementoCostoTO elem = (ElementoCostoTO) this.jcboElemento.getSelectedItem();
            ElementoCosto e = new ElementoCosto(elem.getId());
            e.setDescElemento(elem.getDescripcion());
            costeo.setIdElementoCosto(e);
            Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
            costeo.setFechaOrden(fecha);
            GestionPedidosDelegate.getInstance().insertaCosteoDiario(costeo);
            Utiles_MensajesDialogo.mensajeInfo("Operacion realizada satisfactoriamente");
            costeo = null;
            limpiar();
        } catch (NumberFormatException ne) {
            Utiles_MensajesDialogo.mensajeAlerta("Ingrese un numero valido");
        } catch (Exception ex) {
            Utiles_MensajesDialogo.mensajeError("Revise sus datos");
        }
}//GEN-LAST:event_jbGuardarActionPerformed

    private void jbGuardarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbGuardarKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == evt.VK_ENTER) {
            jbGuardar.doClick();
        }
}//GEN-LAST:event_jbGuardarKeyPressed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbCancelarKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == evt.VK_ENTER) {
            jbCancelar.doClick();
        }
}//GEN-LAST:event_jbCancelarKeyPressed

    private void jtfCodSuministroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCodSuministroActionPerformed

        if (this.jtfCodSuministro.getText().trim().length() < 1) {
            this.jtfDescSuministro.requestFocus();
        } else {
            buscarSuministros();
        }
}//GEN-LAST:event_jtfCodSuministroActionPerformed

    private void jtfDescSuministroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDescSuministroActionPerformed

        buscarSuministros();
}//GEN-LAST:event_jtfDescSuministroActionPerformed

    private void jtfDescSuministroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescSuministroKeyPressed

        if (this.jtfCodSuministro.getText().trim().length() > 0) {
            this.jtfCodSuministro.setText("");
        }
}//GEN-LAST:event_jtfDescSuministroKeyPressed

    private void jtxRucProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxRucProveedorActionPerformed

        if (this.jtxRucProveedor.getText().trim().length() < 1) {
            this.jtfFecha.requestFocus();
        } else {
            buscarRazonSocial();
        }
}//GEN-LAST:event_jtxRucProveedorActionPerformed

    private void jtxProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxProveedorActionPerformed

        buscarRazonSocial();

        //   this.detallePedido.clear();
        // this.actualizaTablaDetalle();
}//GEN-LAST:event_jtxProveedorActionPerformed

    private void jtxProveedorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtxProveedorKeyPressed
        if (this.jtxRucProveedor.getText().trim().length() > 0) {
            this.jtxRucProveedor.setText("");
        }
}//GEN-LAST:event_jtxProveedorKeyPressed

    private void jtfFechaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFechaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.jtfCantidad.requestFocus();
        }
}//GEN-LAST:event_jtfFechaKeyPressed

    private void jtfCantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCantidadActionPerformed
    }//GEN-LAST:event_jtfCantidadActionPerformed

    private void jftMonto_dolaresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jftMonto_dolaresActionPerformed
    }//GEN-LAST:event_jftMonto_dolaresActionPerformed

    private void jcboElementoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboElementoActionPerformed
}//GEN-LAST:event_jcboElementoActionPerformed

    private void jcboElementoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboElementoKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.jtxProveedor.requestFocus();
        }
}//GEN-LAST:event_jcboElementoKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                jdCosteoDiario dialog = new jdCosteoDiario(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private Costos.CboBeanBindingElementoCosto cboBeanBindingElementoCosto1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JComboBox jcboElemento;
    private javax.swing.JTextField jftMonto_dolares;
    private javax.swing.JLabel jlblMoneda;
    private javax.swing.JTextField jtfCantidad;
    private javax.swing.JTextField jtfCodSuministro;
    private javax.swing.JTextField jtfDescSuministro;
    private javax.swing.JTextField jtfDescripcion;
    private javax.swing.JFormattedTextField jtfFecha;
    private javax.swing.JTextField jtxProveedor;
    private javax.swing.JFormattedTextField jtxRucProveedor;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private void limpiar() {
        this.jtfCantidad.setText("");
        this.jtfCodSuministro.setText("");
        this.jtfDescSuministro.setText("");
        this.jtfDescripcion.setText("");
        this.jtfFecha.setText("");
        this.jftMonto_dolares.setText("");
        this.jcboElemento.setSelectedIndex(0);
        this.jtxProveedor.setText("");
        this.jtxRucProveedor.setText("");
    }
}
